
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#include "DPin.h"


DPin::DPin(void)
{
	this->m_pinDir = PINDIR_NONE;
	this->m_pinLenght = 0;
	this->m_brush.SetStyle(wxNORMAL);
}


DPin::~DPin(void)
{

}

DPin::DPin(wxPoint pos, PIN_DIRECTION pdir, int pinLen)
{
	this->m_pinDir = pdir;
	this->m_pinLenght = pinLen;
	m_pos = pos;
	this->m_brush.SetStyle(wxSOLID);
}

void DPin::Draw(wxDC *dc)
{
	this->SetDrawingTools(dc);
// 	wxPen oldPen;
// 	oldPen = dc->GetPen();
	if(m_pinDir != PINDIR_NONE && m_pinLenght > 0)
	{
		dc->SetPen(wxPen(wxColour(100,100,100), 3, wxSOLID));
		switch(m_pinDir)
		{
		case PINDIR_RIGHT:
			dc->DrawLine(m_pos.x, m_pos.y, m_pos.x + m_pinLenght, m_pos.y);
			break;
		case PINDIR_LEFT:
			dc->DrawLine(m_pos.x, m_pos.y, m_pos.x - m_pinLenght, m_pos.y);
			break;
		case PINDIR_UP:
			dc->DrawLine(m_pos.x, m_pos.y, m_pos.x, m_pos.y - m_pinLenght);
			break;
		case PINDIR_DOWN:
			dc->DrawLine(m_pos.x, m_pos.y, m_pos.x, m_pos.y + m_pinLenght);
			break;
		default:
			break;
		}
	}

	if(this->m_selected == TRUE)
	{
		m_brush.SetColour(255, 0, 0);
		this->SetDrawingTools(dc);
		dc->DrawCircle(m_pos, 5);
	}
	else
	{
		m_brush.SetColour(0, 0, 0);
		this->SetDrawingTools(dc);
		dc->DrawCircle(m_pos, 5);
	}
}

float DPin::GetArea()
{
	return 25.f * 3.1415192f; 
}

bool DPin::PointInside(wxPoint *pnt)
{
	float distance = sqrt(pow((float)(pnt->x - this->m_pos.x), 2) + pow((float)(pnt->y - this->m_pos.y), 2));

	int rad = 0;
	if(5 < 0)
		rad = -5;
	else
		rad = 5;

	if(distance <= (float)rad)
		return TRUE;
	else
		return FALSE;
}

void DPin::ConvertToText(wxString *str)
{
	*str << wxT("pin\t") << this->m_pinDir << wxT("\t") << this->m_pinLenght << wxT("\t") << this->m_pos.x << wxT("\t") << m_pos.y << wxT("\n");
}

wxPoint DPin::GetTopLeft(void)
{
	switch(m_pinDir)
		{
		case PINDIR_RIGHT:
			return this->m_pos;

		case PINDIR_LEFT:
			return wxPoint(m_pos.x - this->m_pinLenght, m_pos.y);
			
		case PINDIR_UP:
			return wxPoint(m_pos.x, m_pos.y - this->m_pinLenght);
			
		case PINDIR_DOWN:
			return this->m_pos;
			
		default:
			return this->m_pos;
			return m_pos;
		}

	return m_pos;
}

wxPoint DPin::GetBottomRight(void)
{
	switch(m_pinDir)
	{
	case PINDIR_RIGHT:
		return wxPoint(m_pos.x + this->m_pinLenght, m_pos.y);

	case PINDIR_LEFT:
		return wxPoint(m_pos.x, m_pos.y);

	case PINDIR_UP:
		return wxPoint(m_pos.x, m_pos.y);

	case PINDIR_DOWN:
		return wxPoint(m_pos.x, m_pos.y + this->m_pinLenght);

	default:
		return this->m_pos;
		return m_pos;
	}

	return m_pos;
}